define(['store'], function (store) {
    'use strict';
    function ctrl($scope,$state, $stateParams,$ionicLoading, LocalCacheService, DeviceService, CommonService, WebService) {
        var userInfo = LocalCacheService.getUser();

        function init() {
            $scope.user = {
                name: userInfo.client_name
            }
        }

        $scope.$on('$ionicView.beforeEnter', function () {
            init()
        });

        $scope.video = function () {
            //视频验证成功返回
            var params = {
                user_id: userInfo.user_id,
                client_name:userInfo.client_name,
                branch_no:userInfo.branch_no,
                businessNumber: '2'
            };


            DeviceService.asyncVideo(params, function (data) {
                $ionicLoading.show();
                if (data.error_no == 0) {
                    var exchange_kind=store.get('exchange_kind');
                    var params = {exchange_kind: exchange_kind, sc_open_flag: 1};
                    WebService.addStockAccount(params).then(function (data) {
                        $ionicLoading.hide();
                        if (data.error_no != 0&&data.error_info) {
                            CommonService.showAlert({message: data.error_info});
                            return;
                        }
                        CommonService.showComplete('../view/template/accounttemplate.html', '返回首页', 'tab.account-index');
                    },function (result) {
                        $ionicLoading.hide();
                        CommonService.showAlert({message: CommonService.getErrorInfo(result)});
                    });
                } else if (data.error_no == 2) {
                    $ionicLoading.hide();
                    $state.go('tab.account-openAccountId');
                } else {
                    $ionicLoading.hide();
                    if (data.errorInfo) {
                        CommonService.showAlert({message: data.errorInfo});
                    }
                }
            })
        }
    }

    ctrl.$inject = ['$scope',  '$state','$stateParams','$ionicLoading', 'LocalCacheService', 'DeviceService', 'CommonService', 'WebService'];
    return ctrl;
});